/* 
 * oms，一个基于J2EE架构运营支撑平台
 * Copyright © GrayRabbit Co., Ltd. All rights reserved.
 * Department:运营department
 * 更多信息请访问：
 * http://code.google.com/p/gray-rabbit-cms/
 */
package org.grayrabbit.cms.service.publish.impl;

import org.grayrabbit.cms.dao.publish.PublishConfigDao;
import org.grayrabbit.cms.entity.OperLog;
import org.grayrabbit.cms.entity.PublishConfig;
import org.grayrabbit.cms.service.publish.PublishConfigService;
import org.grayrabbit.cms.vo.publish.PublishConfigBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import org.grayrabbit.dao.util.Page;
import org.grayrabbit.service.impl.GenericServiceImpl;
/**
 * <b>OperLog</b>的service实现类，事务加此处：

 * @version 1.0,创建时间: 2012-01-05 17:51:19  
 */
@Service
@Transactional
public class PublishConfigServiceImpl extends GenericServiceImpl implements PublishConfigService {
	/**
	 * 注入dao层：
	 */
	@Autowired
	@Qualifier("publishConfigDaoImpl")
	private PublishConfigDao publishConfigDao;
	
	/**
	 * 此方法执行时为只读事务：
	 * @see PublishConfigService#getOperLog(String)
	 */
	@Transactional(readOnly=true)
	public PublishConfig getPublishConfig(final String publishId){
		PublishConfig publishConfig = publishConfigDao.findById(publishId);
		publishConfigDao.initialize(publishConfig);
		return publishConfig;
	}
	
	/**
	 * @see PublishConfigService#delete(String)
	 */
	@Transactional
	public void delete(final PublishConfig publishConfig) {
		publishConfigDao.makeTransient(publishConfig);
	}
	
	/**
	 * @see PublishConfigService#save(OperLog)
	 */
	@Transactional
	public void save(final PublishConfig publishConfig) {
		publishConfigDao.makePersistent(publishConfig);		
	}
	
	/**
	 * 此方法执行时为只读事务：
	 * @see PublishConfigService#getPage(PublishConfigBean)
	 */
	@Transactional(readOnly=true)
	public Page<PublishConfig> getPage(final PublishConfigBean publishConfigBean){
		Page<PublishConfig> page =  new Page<PublishConfig>();
		page.setTotal(publishConfigDao.count(publishConfigBean));
		page.setResult(publishConfigDao.findByQc(publishConfigDao.assembly(publishConfigBean)));
		return page;
	}

	/**
	 * 此方法执行时为只读事务：
	 * @see PublishConfigService#list(Page, PublishConfigBean)
	 */
	public void list(Page<PublishConfig> page, PublishConfigBean publishConfigBean) {
		if(page==null)
			return;
		if(page.isAutoCount()){
			page.setTotal(publishConfigDao.count(publishConfigBean));
		}
		page.setResult(publishConfigDao.findByPage(page,publishConfigBean));
	}
	
	/**
	 * 根据主键id列删除，批量删除OperLog
	 * @see PublishConfigService#delete(String[])
	 */
	public void delete(final String[] key) {
		int i =0;
		for(String id : key){
			publishConfigDao.makeTransient(publishConfigDao.findById(id));
			i++;
			if(i==MAX_CLEAR)
				publishConfigDao.clear();
		}
		
	}
 
}